import axios from 'axios'
import utils from "../common/utils";


export function request(config) {


    const instance = new axios.create({
        baseURL: 'http://150.158.36.242:10030',
        timeout: 8000,
        headers: {
            "Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
        }
    });

    //请求拦截器
    instance.interceptors.request.use(config => {


        let token = utils.localGetItem('token')

        if (token) {
            config.headers.Authorization = "Bearer" + ' ' + token
        }


        return config

    }, error => {
        return error

    })
    instance.interceptors.response.use(res => {

        return res

    }, error => {

        let data = error.response.data

        if (data.code === 40301) {

            utils.localRemoveItem('token')
            alert('你的登录已经过期了！')

            window.location.href = '/login'

        }
        return Promise.resolve(error.response)
    })
    return instance(config)
}



